package com.tools.module.base.web;

import com.tools.common.config.AbstractController;
import com.tools.common.model.Result;
import com.tools.common.util.DateUtils;
import com.tools.common.util.ShiroUtils;
import com.tools.module.base.entity.BaseCompany;
import com.tools.module.base.service.BaseCompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/base/company")
public class BaseCompanyController extends AbstractController {

    @Autowired
    private BaseCompanyService companyService;

    /**
     * 列表
     */
    @PostMapping("/list")
    public Result list(BaseCompany company){
        return companyService.list(company);
    }
    /**
     * 查询
     */
    @PostMapping("/get")
    public Result get(Long id){
        return companyService.get(id);
    }
    /**
     * 保存
     */
    @PostMapping("/save")
    public Result save(@RequestBody BaseCompany company){
        if (company.getId()==null){
            company.setCreateTime(DateUtils.getTimestamp());
            company.setCreateUid(ShiroUtils.getUserId());
        }
        company.setUpdateUid(ShiroUtils.getUserId());
        return companyService.save(company);
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    public Result delete(Long id){
        return companyService.delete(id);
    }
}
